/* export default function access(initialState: { currentUser?: API.CurrentUser } | undefined) {
  const { currentUser } = initialState ?? {};
  return {
    canAdmin: currentUser && currentUser.access === 'admin',
    normalRouteFilter: (route) => hasRoutes.includes(route.name), // initialState 中包含了的路由才有权限访问
  };
}
 */

import { InitialStateType } from ' @umijs/max';

export default function (initialState: InitialStateType) {
  const { currentUser } = initialState || {};
  return {
    normalRouteFilter: (/* route: { path: string } */) => {
      return true; /* currentUser?.permissions.includes(route.path.slice(1).replace('/', '.')); */
    }, // initialState 中包含了的路由才有权限访问
    canView: (page: string) => currentUser && currentUser.permissions?.includes(page + '.page'),
    canEdit: (page: string) => currentUser && currentUser.permissions?.includes(page + '.update'),
    canDelete: (page: string) => currentUser && currentUser.permissions?.includes(page + '.delete'),
    canCreate: (page: string) => {
      return currentUser && currentUser.permissions?.includes(page + '.create');
    },
  };
}
